﻿using UnityEngine;
using System;


namespace PBRSystem.Coord
{
    public class PBRRay
    {
        #region Variables
        private PBRPoint3 _origin;
        private PBRVector3 _direction;
        private float _tMax,_time;
        #endregion

        #region Reporter
        public PBRPoint3 Origin { get => _origin; set => _origin = value; }
        public PBRVector3 Direction { get => _direction; set => _direction = value; }
        public float TMax { get => _tMax; set => _tMax = value; }
        public float Time { get => _time; set => _time = value; }
        #endregion

        #region Contructor
        public PBRRay()
        {
            _tMax = float.PositiveInfinity;
            _time = 0.0f;
        }
        public PBRRay(PBRPoint3 o, PBRVector3 d, float tMax = float.PositiveInfinity, float t = 0.0f)
        {
            _origin = o;
            _direction = d;
            _tMax = tMax;
            _time = t;
        }

        public PBRRay(PBRRay r)
        {
            _origin = r.Origin;
            _direction = r.Direction;
            _tMax = r.TMax;
            _time = r.Time;
        }


        #endregion

        #region Operation
        public PBRPoint3 GetPosition(float t)
        {
            return _origin + _direction * t;
        }

        public virtual bool HasNaNs()
        {
            return float.IsNaN(_tMax) || float.IsNaN(_time) || _origin.HasNaNs() || _direction.HasNaNs();
        }

        #endregion
    }
}


